package com.laiketui.app.controller.activitie;

import com.laiketui.app.api.activitie.PlatformActivitiesService;
import com.laiketui.core.annotation.ParamsMapping;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.root.annotation.HttpApiMethod;
import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 平台活动管理
 *
 * @author Trick
 * @date 2021/4/25 9:49
 */
@Api(tags = "插件-平台活动管理")
@RestController
@RequestMapping("/platform")
public class PlatformActivitiesAction {

    @Autowired
    private PlatformActivitiesService platformActivitiesService;

    @ApiOperation("店铺-平台活动首页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mchId", value = "店铺id", required = true, dataType = "int", paramType = "form")
    })
    @PostMapping("/index")
    @HttpApiMethod(urlMapping = "app.platform_activities.index")
    public Result index(MainVo vo, @ParamsMapping("mch_id") Integer mchId) {
        try {
            return Result.success(platformActivitiesService.index(vo, mchId));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("店铺-活动详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int", paramType = "form")
    })
    @PostMapping("/activity_details")
    @HttpApiMethod(urlMapping = "app.platform_activities.activity_details")
    public Result activityDetails(MainVo vo, @ParamsMapping("id") Integer id) {
        try {
            return Result.success(platformActivitiesService.activityDetails(vo, id));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("店铺-活动商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "mchId", value = "店铺id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "type", value = "0商品列表 1.待审核", required = true, dataType = "int", paramType = "form")
    })
    @PostMapping("/pro_list")
    @HttpApiMethod(urlMapping = "app.platform_activities.pro_list")
    public Result proList(MainVo vo, @ParamsMapping("id") Integer id, @ParamsMapping("mch_id") Integer mchId, int type) {
        try {
            return Result.success(platformActivitiesService.proList(vo, id, mchId, type));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("编辑商品,重新提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "activityType", value = "活动类型", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "type", value = "审核状态 0=撤销 1=提交,不传则删除", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "num", value = "数量", dataType = "int", paramType = "form")
    })
    @PostMapping("/modify_pro")
    @HttpApiMethod(urlMapping = {"app.platform_activities.modify_pro", "app.platform_activities.del_pro"})
    public Result modifyPro(MainVo vo, @ParamsMapping("id") Integer id, String activityType, Integer type, Integer num) {
        try {
            return Result.success(platformActivitiesService.modifyPro(vo, id, activityType, type, num));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }
    @ApiOperation("追加库存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "activityType", value = "活动类型", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "num", value = "数量", dataType = "int", paramType = "form")
    })
    @PostMapping("/add_num")
    @HttpApiMethod(urlMapping = "app.platform_activities.add_num")
    public Result addStockNum(MainVo vo, @ParamsMapping("id") Integer id, String activityType, Integer num) {
        try {
            return Result.success(platformActivitiesService.modifyPro(vo, id, activityType, 99, num));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("添加活动商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "mchId", value = "店铺id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "cid", value = "分类id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "brandId", value = "品牌id", dataType = "int", paramType = "form"),
    })
    @PostMapping("/listdetail")
    @HttpApiMethod(urlMapping = "app.platform_activities.listdetail")
    public Result listdetail(MainVo vo, @ParamsMapping("platform_activities_id") Integer id,
                             @ParamsMapping("mch_id") Integer mchId, Integer cid, @ParamsMapping("brand_id") Integer brandId,
                             @ParamsMapping("product_title") String goodsName, @ParamsMapping("activityType") String type) {
        try {
            return Result.success(platformActivitiesService.listdetail(vo, id, mchId, cid, brandId, goodsName, type));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("添加秒杀商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "mchId", value = "店铺id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "goodsData", value = "商品参数", dataType = "string", paramType = "form"),
    })
    @PostMapping("/add_ms_pro")
    @HttpApiMethod(urlMapping = "app.platform_activities.add_ms_pro")
    public Result addSecondGoods(MainVo vo, int id, @ParamsMapping("mch_id") int mchId, @ParamsMapping("data") String goodsData) {
        try {
            return Result.success(platformActivitiesService.addSecondGoods(vo, id, mchId, goodsData));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("添加拼团商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "mchId", value = "店铺id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "goodsData", value = "商品参数", dataType = "string", paramType = "form"),
    })
    @PostMapping("/add_pt_pro")
    @HttpApiMethod(urlMapping = "app.platform_activities.add_pt_pro")
    public Result addGroupGoods(MainVo vo, int id, @ParamsMapping("mch_id") int mchId, @ParamsMapping("data") String goodsData) {
        try {
            return Result.success(platformActivitiesService.addGroupGoods(vo, id, mchId, goodsData));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

}
